<?php
	header('Content-Type:text/html;Charset=utf-8');
	header("Access-Control-Allow-Origin:*");
	header("Access-Control-Allow-Methods:GET,POST");
	//将拿到的数据提交给数据库
	//(1)连接process数据库
	$conn=mysqli_connect('localhost:3306','root','sdo2605587','process');
	// $conn=mysqli_connect('127.0.0.1','root','root','process');
	//为数据库指定字符集
	if (mysqli_connect_error()) {
    die("数据库连接失败: " . mysqli_connect_error());
	}
	mysqli_query($conn,'SET NAMES utf8');
	//(2)选择特定的数据库
	//mysqli_select_db($conn, 'process');

	//发送SQL语句
	$sql="SELECT name,score FROM score ORDER BY score DESC";
	//(3)执行SQL
	$result = mysqli_query($conn, $sql);
	//INSERT/DELETE/UPDATE 返回：true/false
	//SELECT:false / mysqli_result
	$arr=array();
	for($i=0;$i<10;$i++){
		$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
		$arr[]=$row;		
	};
	// while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){  
	// $arr[]=$row;  
	// };
	echo json_encode($arr);//转化为json对象
	//(5)关闭连接
	//mysqli_close($conn);

	//给客户端以提示：数据保存成功
?>